<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/6/26
 * Time: 16:59
 */

namespace Weixin\Service;


use Common\Common\Service;
use Weixin\Component\Config\ConfigComponent;
use Weixin\Exception\WeixinException;
use Weixin\Response\FindConfigResponse;

class FindConfigService implements Service
{
    public function run()
    {
        $component = new ConfigComponent();
        $response = new FindConfigResponse();
        try {
            $result = $component->findConfig();
            if (empty($result['appid']) == true) {
                $response->setAppIdNull();
            } else {
                $response->setAppId($result['appid']);
            }
            if (empty($result['appsecret']) == true) {
                $response->setAppSecretNull();
            } else {
                $response->setAppSecret($result['appsecret']);
            }
            if (empty($result['encodingaeskey']) == true) {
                $response->setEncodingaeskeyNull();
            } else {
                $response->setEncodingaeskey($result['encodingaeskey']);
            }
            if (empty($result['token']) == true) {
                $response->setTokenNull();
            } else {
                $response->setToken($result['token']);
            }
        } catch (WeixinException $e) {
            throw new WeixinException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}